<%--
  Created by IntelliJ IDEA.
  User: Lin
  Date: 2021/4/28
  Time: 15:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<link rel="stylesheet" href="${pageContext.servletContext.contextPath}/static/layui/css/layui.css">
<script src="${pageContext.servletContext.contextPath}/webjars/jquery/3.1.1/jquery.min.js"></script>
<script src="${pageContext.servletContext.contextPath}/static/layui/layui.js"></script>

<form class="layui-form" action="" style="margin-top: 20px;
margin-right: 50px;
" lay-filter="medicine">
    <div class="layui-form-item">
        <label class="layui-form-label">药品名称</label>
        <div class="layui-input-block">
            <input type="text" name="medicineName" required lay-verify="required" placeholder="药品名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">生产日期</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="manufactureDate"
                   id="manufactureDate" placeholder="yyyy-MM-dd">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">生产商</label>
        <div class="layui-input-block">
            <input type="text" name="manfacturer" required lay-verify="required" placeholder="生产商" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">主要功效</label>
        <div class="layui-input-block">
            <input type="text" name="mainEffect" required lay-verify="required" placeholder="主要功效" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">禁忌</label>
        <div class="layui-input-block">
            <input type="text" name="taboos" required lay-verify="required" placeholder="禁忌" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            <input type="text" name="inventory" required lay-verify="required" placeholder="库存" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-block">
            <input type="text" name="unitDesc" required lay-verify="required" placeholder="单位" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="submit">创建
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script !src="">
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#manufactureDate' //指定元素
            , type: 'datetime'
        });
    });
    layui.use('form', function () {
        var form = layui.form;
        console.log(form);
        //各种基于事件的操作，下面会有进一步介绍
    });
    $("#submit").on("click", function () {
        let form1 = layui.form;
        let val = form1.val("medicine");
        console.log(val);
        $.ajax({
            url: "${pageContext.servletContext.contextPath}/medicine/createMedicine",
            data: val,
            type: "POST",
            dataType: "json",
            async: true,//默认 异步
            success: function (data) {
                console.log(data);
                layer.msg(data.msg);
                if (data.code != 0) {
                    return;
                }
                // 关闭窗口
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中
                // 只有一个会包含信息
                //this; // 调用本次AJAX请求时传递的options参数
            }
        });
    });
</script>